package com.example.jinyongjie.test_opengles.util;

import com.example.jinyongjie.test_opengles.util.Constants;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import static android.opengl.GLES20.*;
import static android.opengl.GLES20.glEnableVertexAttribArray;

/**
 * Created by jinyongjie on 17/3/23.
 */
public class VertexArray {

    private final FloatBuffer m_floatBuffer;
    public VertexArray(float[] vertexData)
    {
        m_floatBuffer = ByteBuffer.allocateDirect(vertexData.length * Constants.BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer();
        m_floatBuffer.put(vertexData);
    }
    public void setVertexAttribPointer(int dataOffset,int attributeLocation,int componentCount,int stride)
    {
        m_floatBuffer.position(dataOffset);
        glVertexAttribPointer(attributeLocation, componentCount, GL_FLOAT,
                true, stride, m_floatBuffer);
        glEnableVertexAttribArray(attributeLocation);

        m_floatBuffer.position(0);
    }
}
